package com.example.eschool.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.example.eschool.R;
import com.example.eschool.fragment.CardFragment;
import com.example.eschool.fragment.HomeFragment;
import com.example.eschool.fragment.MessageFragment;
import com.example.eschool.fragment.PersonFragment;
/**
 * 第一个启动Activity
 */
public class MainActivity extends AppCompatActivity {
    private TextView tv_home;
    private TextView tv_card;
    private TextView tv_message;
    private TextView tv_person;
    private HomeFragment homeFragment;
    private CardFragment cardFragment;
    private MessageFragment messageFragment;
    private PersonFragment personFragment;
    private FragmentTransaction fragmentTransaction;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv_home= findViewById(R.id.tv_home);
        tv_card= findViewById(R.id.tv_card);
        tv_message=findViewById(R.id.tv_message);
        tv_person =findViewById(R.id.tv_person);
        tv_home.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(homeFragment);
            }
        });
        tv_card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(cardFragment);
            }
        });
        tv_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(messageFragment);
            }
        });
        tv_person.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setFragment(personFragment);
            }
        });
        //创建Fragment
        homeFragment=new HomeFragment();
        cardFragment=new CardFragment();
        messageFragment=new MessageFragment();
        personFragment=new PersonFragment();
        setFragment(homeFragment);

    }
    private void setFragment(Fragment fragment){
        fragmentTransaction =getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.layout_container,fragment);
        fragmentTransaction.commit();
    }
//                对应命名
    public void toerweima(View view) {
//                                             这个是你现在这个页面的类   这个是你要跳到哪个页面的类
        Intent intent = new Intent(MainActivity.this, ErweimaActivity.class);
        startActivity(intent);
    }

}

